package org.csu.mypetstore.service;

import org.csu.mypetstore.domain.Category;
import org.csu.mypetstore.domain.Item;
import org.csu.mypetstore.domain.Product;
import org.csu.mypetstore.persistence.CategoryMapper;
import org.csu.mypetstore.persistence.ItemMapper;
import org.csu.mypetstore.persistence.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

@Service
public class CatalogService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ItemMapper itemMapper;

    public Category getCategory(String categoryId) {
        return categoryMapper.getCategory(categoryId);
    }

    //通过类别去得到一系列产品
    public List<Product> getProductListByCategory(String categoryId) {
        return productMapper.getProductListByCategory(categoryId);
    }

    //去得到某一种产品
    public Product getProduct(String productId){
        return productMapper.getProduct(productId);
    }

    //通过产品类别去得到一系列item
    public List<Item> getItemListByProduct(String productId){
        return itemMapper.getItemListByProduct(productId);
    }

    //去得到某一种item
    public Item getItem(String itemId){
        return itemMapper.getItem(itemId);
    }

    public List<Product> searchProductList(String keyword) {
        return productMapper.searchProductList("%"+keyword.toLowerCase()+"%");
    }

    public boolean checkProductId(String str) {
        return productMapper.checkProductId(str);
    }

    public void insertProduct(Product product) {
        productMapper.insertProduct(product);
    }

    public void insertItem(Item item) {
        itemMapper.insertItem(item);
    }

    public void deleteProduct(String productId) {
        productMapper.deleteProduct(productId);
    }

    public void deleteItem(String itemId) {
        itemMapper.deleteItem(itemId);
    }

    public void updateProduct(Product product) {
        productMapper.updateProduct(product);
    }

    public void updateItem(Item item) {
        itemMapper.updateItem(item);
    }

    public ArrayList<Item> getItemList() {
         return itemMapper.getItemList();
    }

    public int getItemAmount() {
        return itemMapper.getItemAmount();
    }

    public void insertInven(String itemId, int supplierId) {
        itemMapper.insertInven(itemId,supplierId);
    }

    public void deleteItemList(String productId) {
        itemMapper.deleteItemList(productId);
    }

    public void deleteInVen(String itemId) {
        itemMapper.deleteInVen(itemId);
    }
}

